void uart0printf(char *str);
void UART0Tx(char c) ;
void init_uart(void);
void delayMs(unsigned int ms);


int main(void){
	
	init_uart();
	while(1){
		uart0printf("ngon lanh canh dao!!!!");
	}
	return 0;
}

void delayMs(unsigned int ms){
	unsigned int i = 0, j = 0;
	
	for (i = 0; i < ms; i++)
		for(j = 0; j < 1590; j++){
			
		}
}

void UART0Tx(char c)  
{
    while((UART0->FR & 0x20) != 0); /* wait until Tx buffer not full */
    UART0->DR = c;                  /* before giving it another byte */
}

void uart0printf(char *str){
	while (*str)
		UART0Tx(*str);
}

void init_uart(void){
	SYSCTL_RCGCUART_R |= uartNum;
	SYSCTL_RCGCGPIO_R | = uartNum;
	
	// set up UART configuration
	UART0_CTL_R = 0;		/* Disable UART0 to set up */
	UART0_CC_R |= (1<<5);			/*UARTCTL->HSE = 0, select ClkDiv = 8*/
	UART0_IBRD_R = 104;		/* 8MHz/8=1MHz (because UARTCTL->HSE = 0 tha means clock/16. If UARTCTL->HSE = 1), 1MHz/104=9600 baud rate */
	UART0_FBRD_R = 11;		/* fraction part, see Example 4-4 */
	UART0_CC_R = 0;			/* Use System Clock.*/
	UART0_CTL_R = 0x301;	/* Enable UART0, TXE, RXE*/
	
	GPIO_PORTA_DEN_R |= 0x03	/* Enable PA0, PA1 as digital*/
	GPIO_PORTA_AFSEL_R |= 0x03	/* Enable PA0, PA1 alteernate function.*/
	GPIO_PORTA_PCTL_R |= 0x11;	/* Config PA0, PA1 to UART PORT*/
	
	delayMs(1);	// Delay for waiting is stabilize.
}